package com.gxa.logistics.service.impl;

import com.github.pagehelper.PageHelper;
import com.gxa.logistics.common.base.PageWrapperDTO;
import com.gxa.logistics.common.base.RespResult;
import com.gxa.logistics.common.util.PageResultUtil;
import com.gxa.logistics.domain.dto.DepartmentReqListDTO;
import com.gxa.logistics.domain.dto.DepartmentSaveDTO;
import com.gxa.logistics.domain.dto.DepartmentUpdateDTO;
import com.gxa.logistics.domain.vo.DepartmentVO;
import com.gxa.logistics.mapper.DepartmentMapper;
import com.gxa.logistics.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public RespResult<PageWrapperDTO<DepartmentVO>> list(DepartmentReqListDTO departmentReqListDTO) {
        // 使用分页插件
        PageHelper.startPage(departmentReqListDTO.getPageNo(), departmentReqListDTO.getPageSize());
        // 包装的分页返回对象
        PageWrapperDTO<DepartmentVO> pageCommon = new PageWrapperDTO<>();
        List<DepartmentVO> departmentList = departmentMapper.findDepartmentByWhere(departmentReqListDTO);
        // 设置分页返回对象
        PageResultUtil.setPageResult(departmentList,pageCommon);
        return RespResult.success(pageCommon);
    }

    @Override
    public void insertDepartment(DepartmentSaveDTO departmentSaveDTO) {
        departmentMapper.insertDepartment(departmentSaveDTO);
    }

    @Override
    public void updateDepartment(DepartmentUpdateDTO departmentUpdateDTO) {
        departmentMapper.updateDepartment(departmentUpdateDTO);
    }

    @Override
    public void deleteDepartmentById(Integer deptId) {
        departmentMapper.deleteDepartmentById(deptId);
    }

    @Override
    public List<DepartmentVO> findAll() {
        List<DepartmentVO> departments = departmentMapper.findAll();
        return departments;
    }


}
